<?php 

$ACL = '<?php

class ACL extends Zend_Controller_Plugin_Abstract
{

    private $db;
	protected $_auth = null;
    protected $_acl = null;

    public function __construct(Zend_Auth $auth, Zend_Acl $acl)
    {
        $this->params = array(
    	\'host\'     => \'127.0.0.1\',
    	\'username\' => \'root\',
    	\'password\' => \'\',
    	\'dbname\'   => \'TESTOWYSTRING\',
    	\'profiler\' => true  
		);
		
    	$this->db = Zend_Db::factory(\'PDO_MYSQL\', $this->params);
    	
    	$this->_auth = $auth;
        $this->_acl = $acl;
        
        $role_result = $this->getAllRole();
        $role_akcje_result = $this->getAllRoleAkcje();

    	$akcje_result = $this->getAllAkcje();
		foreach($akcje_result as $value => $v)
		{
			$this->_acl->add(new Zend_Acl_Resource($v[\'akcja_modul\'].$v[\'akcja_kontroler\'].$v[\'akcja_nazwa\']));
		}        
        foreach ($role_result as $rola)
        {
        	$this->_acl->addRole(new Zend_Acl_Role($rola[\'rola_kod\']));
            $licznik = 1;
            
        	foreach ($role_akcje_result as $rola_akcja)
        	{
        		if ($rola[\'rola_kod\']==$rola_akcja[\'rola_akcja_rola_kod_fk\'])
				{
					$akcja_result = $this->getAkcja($rola_akcja[\'rola_akcja_akcja_id_fk\']);
					$this->_acl->allow($rola[\'rola_kod\'], $akcja_result[\'akcja_modul\'].$akcja_result[\'akcja_kontroler\'].$akcja_result[\'akcja_nazwa\']);
					
					$licznik++;
				}	
        	}	
        }

    }

	public function getAllRole()
	{	
		$select = $this -> db -> select()
						-> from (\'adm_rol_role\')
							;

		$s = $this -> db -> fetchAll( $select );
        return $s;
	}    

	public function getAllRoleAkcje()
	{	
		$select = $this -> db -> select()
						-> from (\'adm_rol_role_akcje\')
							;

		$s = $this -> db -> fetchAll( $select );
        return $s;
	}	

	public function getAkcja($akcja_id)
	{
		$select = $this -> db -> select()
						-> from (\'adm_rol_akcje\')
						-> where(\'akcja_id = \'.$akcja_id);

		$s = $this -> db -> fetchRow( $select );
        return $s;
	}	

	public function getAllAkcje()
	{	
		$select = $this -> db -> select()
						-> from (\'adm_rol_akcje\')
							;

		$s = $this -> db -> fetchAll( $select );
        return $s;
	}	
	
	public function preDispatch(Zend_Controller_Request_Abstract $request)
    {	
		//--------
    	$front = Zend_Controller_Front::getInstance();
        $dispatcher = $front->getDispatcher();
        
    	//--------
    	$resources_action = $request->getActionName();
    		
		$resources_kontroler = $request->getControllerName();
    	$resources_modul = $request->getModuleName();
    
    	if($zalogowany = (Zend_Auth::getInstance()->hasIdentity()))
		{
  			$role = (Zend_Auth::getInstance()->getIdentity());
 
    		if (!$this->_acl->isAllowed($role->{\'rola\'}, $resources_modul.$resources_kontroler.$resources_action) && $dispatcher->isDispatchable($request))
    		{   			
    			
    			echo \'Brak uprawnien :(\';
    			exit(0);
    			//$request->setModuleName(\'cms\')
              	//		->setControllerName(\'auth\')
              	//		->setActionName(\'login\');   			
    		}
		}
		else
		{					
			if( $resources_action !== \'login\' && $resources_action !== \'identify\' && $resources_action !== \'logout\' 
				&& $resources_modul !==\'default\' )
			{
				$this->_request->setControllerName(\'Auth\');
				$this->_request->setActionName(\'login\');
				$this->_response->setRedirect(\'Logowanie.html\');
			}		
					
		}	
    	
    }
}
';

//-------------Autoryzacja---------------------------------------------------------------------//
$AuthController = '<?php

class cms_AuthController extends Zend_Controller_Action
{
	
	public function init()
	{
		# Inicjalizacja flashMessengera
		# @see http://blog.adryjanek.eu/2009/01/07/zend-framework-smarty-flashmessenger-helper/
		$this->_flashMessenger = $this->_helper->getHelper(\'FlashMessenger\'); 

    	# Ustawianie folderu z layoutami
    	$this->_helper->layout->setLayoutPath(APPLICATION_PATH.\'/modules/cms/layouts\');
	}

	 public function indexAction()
	 {
	 	$this->_forward(\'login\');
	 }
	 
	 /**
	  * Akcja odpowiada wyświetlanie formularza logowania.
	  */
	 
	 public function loginAction()
	 {
	 	# Jesli uzytkownik jest juz zalogowany to przenosi do panelu
		$auth = Zend_Auth::getInstance();
		if ( $auth->hasIdentity()) {
			$this->_redirect(\'CMS,Listuj_strony,1.html\');
		}
		
	 	# Ustawianie layoutu logowania: \'layouts/logowanie.phtml\'
		$this->_helper->layout->setLayout(\'logowanie\');
		
	 	# Formularz logowania
	 	$form = $this->view->form = new LoginForm();
	 	$form->setAction(\'cms/auth/identify\');
		
	 	# Przekazywanie informacji między akcjami
	 	$this->view->messages = $this->_flashMessenger->getMessages();
	 	
	 	# Tytuł
	 	$this->view->headTitle(\'Logowanie do systemu\');
	 }
	 
 	/**
 	 * Akcja uwierzytelnia dane uzytkownika.
 	 */
	 
	 public function identifyAction()
	 {
	 	# Jesli uzytkownik jest juz zalogowany to przenosi do panelu
		$auth = Zend_Auth::getInstance();
		if ( $auth->hasIdentity()) {
			$this->_redirect(\'CMS,Listuj_strony,1.html\');
		}
		
	  	$success = false;
	  	  
	  	if ($this->_request->isPost()) 
	  	{

			$formData = $this->_request->getPost();
        
			if ( empty( $formData[ admUzyUzytkownicy::uzytkow_login ] ) || empty( $formData[ admUzyUzytkownicy::uzytkow_haslo ]) ) 
			{
				$this->_flashMessenger->addMessage("Wprowadź poprawny login i hasło!" ); 
			}
			else 
			{
	            # do the authentication
	            $authAdapter = $this->_getAuthAdapter( $formData );              
	            $auth = Zend_Auth::getInstance();
	            $result = $auth->authenticate( $authAdapter );

				if ( $result->isValid() )
				{
                	# success: store database row to auth storage
                	# (Not the password though!)
					$data = $authAdapter->getResultRowObject( null, admUzyUzytkownicy::uzytkow_haslo );
					
					# dodanie roli do uzytkownika 
					$rola_uzytkownik = new admRolRoleUzytkownicy();	

					$user_id = $data->uzytkow_id;					
					$rola = $rola_uzytkownik->selectOne(NULL,array(\'rola_osoby_uzytkownik_id_fk = \'.$user_id));
					# przypisanie do daty nowego pola - roli
					$data->rola = $rola[admRolRoleUzytkownicy::rola_osoby_rola_kod_fk]; 
					//die(print_r($data));
					$auth->getStorage()->write( $data );
					$success = true;
					    
					$redirectUrl = \'CMS,Listuj_strony,1.html\';
             	}
				else
				{
					$this->_flashMessenger->addMessage( "Logowanie nie powiodło się." );
				}
			}
		}

	    if( !$success ) 
	    {
	        $flashMessenger = $this->_helper->FlashMessenger;
	        $flashMessenger->setNamespace(\'actionErrors\');

	        $redirectUrl = \'Logowanie.html\';
	 	}

        $this->_redirect( $redirectUrl );
	}

	/**
	 * Metoda zwracająca adapter do autentykacji opartej na bazie danych
	 * @param $formData
	 */

	protected function _getAuthAdapter( $formData )
	{
		# @see http://devzone.zend.com/article/1264
		$config = new Zend_Config_Ini( APPLICATION_PATH.\'/configs/application.ini\',
	  							       \'staging\');

		# tworzenie adaptera
		$dbAdapter = Zend_Db::factory( $config->resources->db );

		# tworzenie autentykacyjnego adaptera bazodanowego
		$authAdapter = new Zend_Auth_Adapter_DbTable( $dbAdapter );

		# konfiguracja adaptera
		$authAdapter->setTableName( \'adm_uzy_uzytkownicy\' )
 	    	        ->setIdentityColumn( admUzyUzytkownicy::uzytkow_login )
                    ->setCredentialColumn( admUzyUzytkownicy::uzytkow_haslo );                               

		# haszowanie hasła
		$password = md5( $formData[ admUzyUzytkownicy::uzytkow_haslo ] );            
		$authAdapter->setIdentity( $formData[ admUzyUzytkownicy::uzytkow_login ] );        
		$authAdapter->setCredential( $password );

       return $authAdapter;
	}

	/**
	 * Akcja odpowiedzialna za wylogowanie
	 */
	
	public function logoutAction()
	{
		$auth = Zend_Auth::getInstance();
		$auth->clearIdentity();

		$this->_redirect(\'Logowanie.html\');
	}
}';

$logowanie = '<?php echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">

<head>

	<?php
     $this->headLink()->appendStylesheet( $this->baseUrl().\'/css/panel/panel_style.css\' )
                 	  ->headLink(array( \'rel\' => \'shortcut icon\',
                                        \'href\' => $this->baseUrl().\'/files/intranet/img/fav_32.png\',
                 	  					\'type\' => \'image/x-icon\'),
                                        \'PREPEND\')
                 	  ;

	$this->headScript()//->appendFile( $this->baseUrl().\'/js/default/searchBoxClear.js\', $type = \'text/javascript\', $attrs = array() );
					  ;

	$this->headMeta()->appendName(\'keywords\', \'Information Mastery TESTOWYSTRING\')
					 ->appendName(\'revisit-after\', \'7 Days\')
					 ->appendName(\'robots\', \'index, follow\')
					 ->appendName(\'rating\', \'general\')
					 ->appendName(\'copyright\', \'Information Mastery\')
					 ->appendName(\'author\', \'Information Mastery\')
					 ->appendName(\'reply-to\', \'biuro@information-mastery.pl\')
					 ->appendName(\'description\', \'intranet\')
					 ;

	echo $this->headScript();
	echo $this->headLink();
	echo $this->headTitle();
	echo $this->headMeta();

	?>

</head>

<body>
	<div id="panel_logowania">
	<h1><img src="<?php echo $this->baseUrl(); ?>/files/img_panel/logo_panel.png" alt="logo" title="Information Mastery"/></h1>
	<div id="formularz">

    	<h2>Logowanie</h2>

        <?php echo $this->layout()->content; ?>

	</div>
	</div>

	<div id="footer">
		Copyright &copy; <?php echo date(\'Y\');?> <a href="http://www.information-mastery.pl" title="Information Mastery - Agencja interaktywna" target="_blank">Information Mastery</a> Wszystkie prawa zastrzeżone
	</div>

</body>
</html>	';

$login = '<?php echo $this->form; ?>';

$LoginForm = '<?php

class LoginForm extends Zend_Form
{
    public function __construct( $options = null )
    {
        parent::__construct( $options );
        $this->setName( \'loginForm\' );

        $login = new Zend_Form_Element_Text( admUzyUzytkownicy::uzytkow_login );
        $login->setLabel(\'Login:\' )
        	  ->setRequired( true )
              ->addFilter( \'StripTags\' )
              ->addFilter( \'StringTrim\' )
              ->addValidator( \'NotEmpty\' )
              ->addValidator( \'StringLength\', true, array(2,96) );
        ;

	   	$login->setDecorators(array( \'ViewHelper\', \'Description\', \'Errors\',
	                   //array(array(\'data\'=>\'HtmlTag\'), array(\'tag\' => \'td\')),
	                   array(\'Label\', array(\'tag\' => \'div\')),
	                   array(array(\'row\'=>\'HtmlTag\'),array(\'tag\'=>\'div\',\'class\'=>\'ibox\'))
	           ));

		$haslo = new Zend_Form_Element_Password( admUzyUzytkownicy::uzytkow_haslo );
		$haslo->setLabel( \'Hasło:\' )
				->setRequired( true )
				->addFilter( \'StripTags\' )
				->addFilter( \'StringTrim\' )
				->addValidator( \'NotEmpty\' )
		;
		
	   	$haslo->setDecorators(array( \'ViewHelper\', \'Description\', \'Errors\',
	                   //array(array(\'data\'=>\'HtmlTag\'), array(\'tag\' => \'td\')),
	                   array(\'Label\', array(\'tag\' => \'div\')),
	                   array(array(\'row\'=>\'HtmlTag\'),array(\'tag\'=>\'div\',\'class\'=>\'ibox\'))
	           ));

        $submit = new Zend_Form_Element_Submit(\'Zaloguj\');
        $submit->setLabel(\'Zaloguj się\');
        
      	$submit->setDecorators(array( \'ViewHelper\', \'Description\', \'Errors\', 
      					array(array(\'data\'=>\'HtmlTag\'), array(\'tag\' => \'div\')),
                   		array(array(\'row\'=>\'HtmlTag\'),array(\'tag\'=>\'div\',\'class\'=>\'submit\'))
       	));

        $this->addElements(array( $login, $haslo, $submit));

      	$this->setDecorators(array(
               \'FormElements\',
               array(array(\'data\'=>\'HtmlTag\'),array(\'tag\'=>\'div\')),
               \'Form\'
       	));

       /**
        * Usuwa wszystkie dekoratory błędów
        */
       	
        foreach ($this->getElements() as $element) 
        {
            $element->removeDecorator(\'Errors\');
   		}
    }
    
}';

$AuthRouters = '<?php

#Logowanie.html
$r[\'cmsLogowanie\'] = new Zend_Controller_Router_Route_Regex(
	\'Logowanie.html\',
    array( \'action\' => \'login\', \'controller\' => \'auth\', \'module\' => \'cms\' ),
    array( ),
	\'Logowanie.html\'
);

#Wyloguj.html
$r[\'cmsWyloguj\'] = new Zend_Controller_Router_Route_Regex(
	\'Wyloguj.html\',
    array( \'action\' => \'logout\', \'controller\' => \'auth\', \'module\' => \'cms\' ),
    array( ),
	\'Wyloguj.html\'
);

$router->addRoutes( $r );';

$AclMenuHelper = '<?php
/**
 * Creates an html link depending on Zend_Acl.
 * Automatically adds attributes and parameters.
 * * @author Sergeev Anton xapon91@gmail.com
 * @package View_Helper_Href
 * @copyright Copyright (c) 2010 Sergeev Anton 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL v3 license
 * 
 * @see http://www.zfsnippets.com/snippets/view/id/75/href-view-helper
 */ 
class CMS_View_Helper_AclMenuHelper extends Zend_View_Helper_Url {
        /**
         * @var array
         * Default options
         */             private $options=array(\'controller\'=>null,       	 //default controller
                                                   \'action\'=>\'index\',        //default action
                                                   \'params\'=>array(),        //array of parameters
                                                   \'router\'=>\'default\',      //default router
                                                   \'checkAcl\'=>true,         //check if this link allowed by Zend_Acl                                                   
												   \'content\'=>null,         //Link content, text or what you want between <a> and </a>
                                                   \'attribs\'=>array(),       //Link attributes, e.g. class or id
                                                   \'resource\'=>null,         //ACL resource name, if not set - controller name will be used
                                                   \'resource-prefix\'=>\'mvc:\',//If "resource" option is null, the ACL will be checked with this option connected with "controller" option
                                                   \'privilege\'=>null,        //ACL privilege name, if null - action name will be used                                                   
												   \'reset\'=>true,           //reset router defaults
                                                   \'url\'=>null,              //Url like "http://google.com", will be used if controller is null
                                                   \'acl\'=>\'Acl\',             //Zend_Acl instance. If option is string, will try to get Zend_Acl from Zend_Registry by this string
                                                   \'role\'=>null              //String - role name.      
                                                  ); 
                         private $type = NULL;       
		/**
          * @param array $options 
          * @return string or bool FALSE if options are incorrect or access denied
          */                             
    public function AclMenuHelper(array $options, $type) 
    {        
    	$options=array_merge($this->options, $options);
        
        $url=$this->setUrl($options);
                        
        if (count($options[\'attribs\'])>0) 
        {                                     
        	foreach ($options[\'attribs\'] as $attrib=>$value)
                        $attribs.=$attrib."=\'".$value."\' ";                                                     
        } 
        else
        	$attribs=null;
     	
        	
        	if ($type==\'a\')
        	{
        		$link = \'<a href="\'.$url.\'" \'.$attribs.\' >\'.$options[\'content\'].\'</a>\';
        	}
        	else
        		$link=\'<li \'.$attribs.\' ><a href="\'.$url.\' " >\'.$options[\'content\'].\'</a></li>\';        

        if ( $options[\'checkAcl\']==true )
        {
                if ( $this->checkAcl($options) )
                {
                    return $link; 
               	}
                else
                {
                	return false;
                }
        }
        else 
        return $link;   
    }
    /**
      * Construct URL based on standart url helper 
      * @param array $options
      * @return string      */        
    private function setUrl($options) {
        if ($options[\'controller\']!=null) {
                
                $url=$this->url(array_merge(array(\'controller\'=>$options[\'controller\'],                                                                                   
                								  \'action\'=>$options[\'action\']),
                                                  $options[\'params\']),
                                            	  $options[\'router\'],
                                                  $options[\'reset\']);
                                                    } elseif ($options[\'url\']!=null) {
                $url=$options[\'url\'];
        } else {
                $url=\'#\';
        }        return $url;
    }
    
    /**
      * Check if current options are allowed by Zend_Acl      * @param array $options
      * @return bool
      */
    private function checkAcl($options) 
    {
    	       
        if ( ($options[\'resource\']==null) AND ($options[\'controller\']!=null) ) 
        {                         
        	$resource=$options[\'resource-prefix\'].$options[\'controller\'];
            $privilege=$options[\'action\'];
      
        } 
        elseif ($options[\'resource\']!=null AND $options[\'privilege\']!=null) 
        {
            $resource=$options[\'resource\'];
            $privilege=$options[\'privilege\'];             
        } 
        else
 
		return false;   
		
		 
        if (is_a($options[\'acl\'], \'Zend_Acl\'))
        $acl=$options[\'acl\'];
        
        else 
        {                        
        	if (Zend_Registry::isRegistered(strval($options[\'acl\'])))
            	$acl=Zend_Registry::get($options[\'acl\']);
            else 
            return false;
               
        }                       
        	$role=$options[\'role\'];
        	
            if ($role==null)
            	return false;
            if ($acl->isAllowed($role, $resource, $privilege)) 
            {                                            
                        return true;                
            }
                else 
                        return false;   
    }  
    
}';

$AclMenuOtherHelper = '<?php
/**
 * Creates an html link depending on Zend_Acl.
 * Automatically adds attributes and parameters.
 * * @author Sergeev Anton xapon91@gmail.com
 * @package View_Helper_Href
 * @copyright Copyright (c) 2010 Sergeev Anton 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL v3 license
 * 
 * @see http://www.zfsnippets.com/snippets/view/id/75/href-view-helper
 */ 
class CMS_View_Helper_AclMenuOtherHelper extends Zend_View_Helper_Url {
        /**
         * @var array
         * Default options
         */             private $options=array(\'controller\'=>null,       	 //default controller
                                                   \'action\'=>\'index\',        //default action
                                                   \'params\'=>array(),        //array of parameters
                                                   \'router\'=>\'default\',      //default router
                                                   \'checkAcl\'=>true,         //check if this link allowed by Zend_Acl                                                   
												   \'content\'=>null,         //Link content, text or what you want between <a> and </a>
                                                   \'attribs\'=>array(),       //Link attributes, e.g. class or id
                                                   \'resource\'=>null,         //ACL resource name, if not set - controller name will be used
                                                   \'resource-prefix\'=>\'mvc:\',//If "resource" option is null, the ACL will be checked with this option connected with "controller" option
                                                   \'privilege\'=>null,        //ACL privilege name, if null - action name will be used                                                   
												   \'reset\'=>true,           //reset router defaults
                                                   \'url\'=>null,              //Url like "http://google.com", will be used if controller is null
                                                   \'acl\'=>\'Acl\',             //Zend_Acl instance. If option is string, will try to get Zend_Acl from Zend_Registry by this string
                                                   \'role\'=>null              //String - role name.      
                                                  ); 
                         private $type = NULL;       
		/**
          * @param array $options 
          * @return string or bool FALSE if options are incorrect or access denied
          */                             
    
    public function AclMenuOtherHelper($p_modul,$p_kod, $p_acl, $p_id = NULL)
	{
		$role = (Zend_Auth::getInstance()->getIdentity());
		$bUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
		if ($p_modul==\'strony\')
		{
			//-------------Edycja---------------------------//
			if ($p_kod == 1)
			{
				
				return $this->MenuHelper(
								array(\'router\' => \'cmsStronyEdytujstroneAction\',
									  \'params\' => array(\'id\' => $p_id),
									  \'content\' => \'<img alt="Edytuj" src="\'.$bUrl.\'/files/img_panel/pencil.png" style="border: 0; padding-right: 10px;" />\',
									  \'resource\' => \'cmsstronyedytujstrone\',
										\'acl\' => $p_acl,
									  \'role\' => $role->{\'rola\'},
									  \'privilege\' => \'Edytujstrone\',
										\'controller\' => \'strony\',
										\'action\' => \'Edytujstrone\',
									\'attribs\' => array()
								),\'a\'
							);
				
			}
			//-------------Usuwanie---------------------------//
			else if ($p_kod==2)
			{
				return $this->MenuHelper(
								array(\'router\' => \'cmsStronyUsunstroneAction\',
									  \'params\' => array(\'id\' => $p_id),
									  \'content\' => \'<img alt="Usuń" src="\'.$bUrl.\'/files/img_panel/ico_kosz.gif" style="border: 0; padding-right: 10px;" />\',
									  \'resource\' => \'cmsstronyusunstrone\',
										\'acl\' => $p_acl,
									  \'role\' => $role->{\'rola\'},
									  \'privilege\' => \'usunstrone\',
										\'controller\' => \'strony\',
										\'action\' => \'usunstrone\',
									\'attribs\' => array()
								),\'a\'
							);				
			}
			//-------------Dodawanie---------------------------//
			else if ($p_kod==3)
			{
				return $this->MenuHelper(
								array(\'router\' => \'cmsStronyDodajstroneAction\',
									  \'params\' => array(),
									  \'content\' => \'<img alt="Dodaj stronę" src="\'.$bUrl.\'/files/img_panel/dodajstrone.jpeg" style="border: 0; float: left;" />\',
									  \'resource\' => \'cmsstronydodajstrone\',
										\'acl\' => $p_acl,
									  \'role\' => $role->{\'rola\'},
									  \'privilege\' => \'dodajstrone\',
										\'controller\' => \'strony\',
										\'action\' => \'dodajstrone\',
									\'attribs\' => array()
								),\'a\'
							);				
			}
			
		}
		//--Oznaczenie_miejsca_przed1-------//

	}                       
                         
    public function MenuHelper(array $options, $type) 
    {        
    	$options=array_merge($this->options, $options);
        
        $url=$this->setUrl($options);
                        
        if (count($options[\'attribs\'])>0) 
        {                                     
        	foreach ($options[\'attribs\'] as $attrib=>$value)
                        $attribs.=$attrib."=\'".$value."\' ";                                                     
        } 
        else
        	$attribs=null;
     	
        	
        	if ($type==\'a\')
        	{
        		$link = \'<a href="\'.$url.\'" \'.$attribs.\' >\'.$options[\'content\'].\'</a>\';
        	}
        	else
        		$link= \'<li \'.$attribs.\' ><a href="\'.$url.\' " >\'.$options[\'content\'].\'</a></li>\';        
			
        if ( $options[\'checkAcl\']==true )
        {
                if ( $this->checkAcl($options) )
                {
                	return $link; 
               	}
                else
                {
                	return false;
                }
        }
        else 
        return $link;   
    }
    /**
      * Construct URL based on standart url helper 
      * @param array $options
      * @return string      */        
    private function setUrl($options) {
        if ($options[\'controller\']!=null) {
                
                $url=$this->url(array_merge(array(\'controller\'=>$options[\'controller\'],                                                                                   
                								  \'action\'=>$options[\'action\']),
                                                  $options[\'params\']),
                                            	  $options[\'router\'],
                                                  $options[\'reset\']);
                                                    } elseif ($options[\'url\']!=null) {
                $url=$options[\'url\'];
        } else {
                $url=\'#\';
        }        return $url;
    }
    
    /**
      * Check if current options are allowed by Zend_Acl      * @param array $options
      * @return bool
      */
    private function checkAcl($options) 
    {
    	       
        if ( ($options[\'resource\']==null) AND ($options[\'controller\']!=null) ) 
        {                         
        	$resource=$options[\'resource-prefix\'].$options[\'controller\'];
            $privilege=$options[\'action\'];
      
        } 
        elseif ($options[\'resource\']!=null AND $options[\'privilege\']!=null) 
        {
            $resource=$options[\'resource\'];
            $privilege=$options[\'privilege\'];             
        } 
        else
 
		return false;   
		
		 
        if (is_a($options[\'acl\'], \'Zend_Acl\'))
        $acl=$options[\'acl\'];
        
        else 
        {                        
        	if (Zend_Registry::isRegistered(strval($options[\'acl\'])))
            	$acl=Zend_Registry::get($options[\'acl\']);
            else 
            return false;
               
        }                       
        	$role=$options[\'role\'];
        	
            if ($role==null)
            	return false;
            if ($acl->isAllowed($role, $resource, $privilege)) 
            {                                            
                        return true;                
            }
                else 
                        return false;   
    }
  
}';

$AclMenuGlowne = '<?php
$role = (Zend_Auth::getInstance()->getIdentity());

if ($this->pid==\'strony\')
{
	$strony = \'current\';
}
//--Oznaczenie_miejsca_przed1-------//

//pierwsza pozycja w menu
echo $this->AclMenuHelper(
							array(\'router\' => \'cmsStronyListujstronyAction\',
								  \'params\' => array(\'page\' => 1),
								  \'content\' => \'Strony\',
								  \'resource\' => \'cmsstronylistujstrony\',
									\'acl\' => $this->acl,
								  \'role\' => $role->{\'rola\'},
								  \'privilege\' => \'listujstrony\',
									\'controller\' => \'strony\',
									\'action\' => \'listujstrony\',
									\'attribs\' => array(\'class\' => $strony)
							),\'l\'
						);
//--Oznaczenie_miejsca_przed2-------//	';




//-------------Utworzenie katalogów------------------------------------------------------------//

$dirs = $dirs+array('/application/modules/cms/views/scripts/auth',);

//-------------Utworzenie plików---------------------------------------------------------------//

$files = $files+array('/application/plugins/Acl.php' => $ACL,
					  '/application/forms/LoginForm.php' => $LoginForm,
					  '/application/modules/cms/controllers/AuthController.php' => $AuthController,
					  '/application/modules/cms/layouts/logowanie.phtml' => $logowanie,
					  '/application/modules/cms/views/scripts/auth/login.phtml' => $login,
					  '/application/routers/authRouters.php' => $AuthRouters,					  
  					  '/application/modules/cms/views/helpers/AclMenuHelper.php' => $AclMenuHelper,
					  '/application/modules/cms/views/helpers/AclMenuOtherHelper.php' => $AclMenuOtherHelper,
					  '/application/modules/cms/layouts/AclMenuGlowne.phtml' => $AclMenuGlowne
			   	  );
			   	  
//-------------Zmienienie nazwy bazy danych w plikach do ACLa----------------------------------//
$f_zmien = $f_zmien+array('application/plugins/Acl.php(*)TESTOWYSTRING(*)'.$this->_db_name);
//-------------Dodanie routera auth w indexie------------------------------------------//
$this->znajdzDoklejZa($path_projekt.'/public/index.php','$router = $frontController->getRouter();','include_once \'authRouters.php\';');			   	  		   	  			   	  			   	  

//-------------Zerejestrowanie pluginu ACL w indexie-------------------------------------------//
$this->znajdzDoklejPrzed($path_projekt.'/application/Bootstrap.php','//--Oznaczenie_miejsca_przed1-------//','
  private $_acl = NULL;
  private $_auth = NULL;');

$this->znajdzDoklejPrzed($path_projekt.'/application/Bootstrap.php','//--Oznaczenie_miejsca_przed2-------//','
        $fc = Zend_Controller_Front::getInstance();
   		$this->_auth = Zend_Auth::getInstance();
		$this->_acl = new Zend_Acl();
		
		$fc->setParam(\'auth\', $this->_auth);
		$fc->setParam(\'acl\' , $this->_acl);
		$fc->registerPlugin( new ACL($this->_auth, $this->_acl) );');

$this->znajdzDoklejPrzed($path_projekt.'/application/Bootstrap.php','//--Oznaczenie_miejsca_przed3-------//','
$view->acl = $this->_acl;');

